home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / untested / tcpip / web / file.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  1.2 KB  |  48 lines  |  [TEXT/ttxt]

  1. --<<<
  2.  
  3. in module WebImplementation
  4.  
  5. global fileMIMETypes := new hashTable
  6.  
  7. function getFileMIMEType suffix -> (
  8.     local type := fileMIMETypes[getlowercase(suffix as string)]
  9.     if type == empty do 
  10.         report (new generalexception) #("no mime type for file suffix", suffix)
  11.     type
  12. )
  13.  
  14. fileMIMETypes["htm" as string] := "text/html" as string
  15. fileMIMETypes["html" as string] := "text/html" as string
  16. fileMIMETypes["sxt" as string] := "application/x-scriptx-title" as string
  17. fileMIMETypes["gif" as string] := "image/gif" as string
  18.  
  19. function getfilemethod url -> (
  20.      local file := url.path
  21.     local dirs := new Array
  22.     local n;
  23.     local slash := "/"[1]
  24.  
  25.     if ((size file) > 0 and file[1] = slash) do
  26.         file := copyFromTo file 1 (size file)
  27.  
  28.     repeat while (n := getOrdOne file slash) > 0 do (
  29.         append dirs (copyFromTo file 0 (n - 1))
  30.         file := copyFromTo file n (size file)
  31.     )
  32.  
  33.     local suffix := file
  34.  
  35.     repeat while (n := getOrdOne suffix "."[1]) > 0 do (
  36.         suffix := copyFromTo suffix n (size suffix)
  37.     )
  38.  
  39.     local info := new hashtable
  40.     info["content-type" as string] := getFileMIMEType suffix
  41.  
  42.     #(info, getstream (spawn therootdir dirs)  file @readable)
  43. )
  44.  
  45. registerAccessMethod WebAccessManager "file" getfilemethod
  46.  
  47. -->>>
  48.